package wfm.delegator;

import java.util.Date;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

import wfm.entities.Ticket;
import wfm.query.QueryDao;
import wfm.util.email.Mail;
import wfm.util.email.MailAccounts;


public class HandleTimeOutReminderDelegate implements JavaDelegate {

	public void execute(DelegateExecution execution) throws Exception {
		Date d = new Date();
		System.out.println("Wiederholte Erinnerung starten: " + d);

		Ticket ticket = (Ticket) QueryDao.getVariableToProcessWithExecutionId(
				execution.getId(), "ticket");

		if (ticket != null && ticket.getSelectedPartner() != null) {

			String recipient = ticket.getSelectedPartner().getEmail();
			String subject = "Work Reminder";
			String text = "Please finish your Job for "
					+ ticket.getCustomer().getLastName() + " "
					+ ticket.getCustomer().getFirstName();

			try {
				System.out
						.println("Hier wird dem Worker ein Mail geschickt an: "
								+ recipient);
				//Mail.send(MailAccounts.GMX, recipient, subject, text);
			} catch (Exception e) {
				System.out.println("Problem with sending Mail to: " + recipient);
			}
		}
	}

}